package cn.wolfcode.trip.app.web.controller;

import cn.wolfcode.trip.base.domain.NewsDetail;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.service.INewsDetailService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/news")
public class newsController {

    @Autowired
    private INewsDetailService newsDetailService;

    /**
     * 指定推荐查询日报
     * @param state
     * @return
     */
    @GetMapping("/commend")
    public Object getCommend(@RequestParam Integer state){
        List<NewsDetail> list = newsDetailService.selectNewsByState(state);
        return list;
    }

    /**
     * 查询所有的日报(分页)
     * @param qo
     * @return
     */
    @GetMapping
    public Object list(QueryObject qo){
        PageInfo pageInfo = newsDetailService.query(qo);
        return  pageInfo;
    }

    /**
     * 指定id查询日报
     * @param id
     * @return
     */
    @GetMapping("/detail/{id}")
    public Object get(@PathVariable Long id){
        NewsDetail newsDetail  = newsDetailService.get(id);
        return newsDetail;
    }


}
